---
layout: "default"
title: "Operator: prefix !"
description: "Swift documentation for the 'prefix !' operator."
root: "/v4.2"
---

<code class="language-swift"> operator prefix ! {
    associativity 
    precedence 
}</code>

<h3>Declarations</h3>

<div class="declaration" id="func-excl_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-excl_-bool">prefix func !(<wbr>_: Bool)</a>
        
<div class="comment collapse" id="comment-func-excl_-bool"><div class="p">
    <p>Performs a logical NOT operation on a Boolean value.</p>

<p>The logical NOT operator (<code>!</code>) inverts a Boolean value. If the value is
<code>true</code>, the result of the operation is <code>false</code>; if the value is <code>false</code>,
the result is <code>true</code>.</p>

<pre><code class="language-swift">var printedMessage = false

if !printedMessage {
    print(&quot;You look nice today!&quot;)
    printedMessage = true
}
// Prints &quot;You look nice today!&quot;</code></pre>

<p><strong><code>a</code>:</strong>  The Boolean value to negate.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">prefix func !(a: Bool) -&gt; Bool</code>
    
    
</div></div>
</div>
